/**
 * Created by fdg282 on 2017/9/25.
 */
$(function(){
	$(".data-select").flatpickr({
        minDate:'today'
    });

   new Swiper('#t-service', {
        pagination: '.p1',
        direction: 'vertical',
        slidesPerView: 1,
        paginationClickable: true,
        spaceBetween: 30,
        autoplay:1500,
        mousewheelControl: true,
        paginationType:'fraction',
        effect : 'cube',
        cube: {
            slideShadows: true,
            shadow: true,
            shadowOffset: 100,
            shadowScale: 0.3
        }
    });
});

$('.vip_list').on('click',function(){
    $(".vip_form").removeClass('hide');
    var config_value = $(this).attr('data-config-value');
    $('.vip_form').find('select[name=service_vip]').val(config_value);
    layer.open({
        type: 1,
        title: false,
        closeBtn:1,
        shadeClose: false,
        skin: '.vip_form',
        content: $('.vip_form'),
        success:function(index){
            $('html').css('overflow-y', 'hidden');
            $('.layui-layer-close').bind('click',function(){
                layer.closeAll();
                $('html').css('overflow-y', 'auto');
                $(".vip_form").addClass('hide');
                if($('#flatpickr-tryme').hasClass('active')){
            		$('#flatpickr-tryme').removeClass('active');
                	$('.flatpickr-calendar').removeClass('open');
            	}
            });
        }
    });
});

$('.check_input').on('click',function(){
	if($('#flatpickr-tryme').hasClass('active')){
		$('#flatpickr-tryme').removeClass('active');
    	$('.flatpickr-calendar').removeClass('open');
	}else{
		var height = $('#flatpickr-tryme').offset().top + 32;
    	var left = $('#flatpickr-tryme').offset().left;
		$('#flatpickr-tryme').addClass('active');
		$('.flatpickr-calendar').addClass('open arrowTop');
		$('.flatpickr-calendar').css({top:height+'px',left:left+'px'});
	}
});

$('.service-vip-submit').on('click',function(){
	var form = $('#save-service-vip');
	$.post(form.attr('action'),form.serialize(),success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
        	window.location.reload();
        }else{
            $('.err-info').text(data.val);
        }
    }
});

var reg = /^1(0|1|2|3|4|5|6|7|8|9)\d{9}$/;
$('.cust_tel').keyup(function () {
    var userphone = $(this).val();
    if (userphone <= 0) {
        $('.err-info').removeClass('hide');
        $('.err-info').text('手机号不能为空');
    } else if (!reg.test(userphone)) {
    	$('.err-info').removeClass('hide');
        $('.err-info').text('请输入正确的11位手机号');
    } else {
    	$('.err-info').addClass('hide');
    }
});